<template>
	<view>
		<view class="title">金额</view>
		<view class="price">￥{{(Number(data.house_deposit)).toFixed(2)}}</view>
		<view class="u-flex user">
			<view>收款方</view>
			<view>房联网</view>
		</view>
		<view class="pay-btn">
			<u-button type="success" shape="circle" @click="pay">支付</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:'',
				orderId:''
			}
		},
		methods: {
			pay(){
				if(this.orderId){
					this.doPay(this.orderId)
					return
				}
				this.$u.post('/api/user/payDeposit',{
					build_type:this.data.type,//类型 新房二手房...
					house_id:this.data.id,
					status:this.data.types === '1' ? 1 : 2, //1意向金，2定金
					admin_housekeeper_id:this.data.ids,//管家
					price:this.data.house_deposit,
					pay_method:0,
					realname:this.data.realname,
					phone:this.data.phone
				}).then(res=>{
					this.orderId = res.id
					this.doPay(res.id)
				})
			},
			doPay(id){
				this.$u.post('/api/pay/submitOrder',{
					house_deposit:id,
					amount:this.data.house_deposit
				}).then(res=>{
					uni.requestPayment({
						...res,
						success: (res) => {
							this.jump('/pages/house/pay/pay-success',!0)
						},
						fail: (err) => {
							this.$u.toast('支付错误')
						}
					})
				})
			}
		},
		onLoad({data}) {
			this.data = JSON.parse(decodeURIComponent(data));
			console.log(this.data,77)
		}
	}
</script>

<style lang="scss">
	.title{text-align: center;padding-top: 50rpx;font-weight: bold;}
	.price{text-align: center;padding-top: 30rpx;font-size: 50rpx;}
	.user{justify-content: space-between;padding:50rpx 30rpx 30rpx;color: #666;border-bottom: 1rpx solid #ddd;}
	.pay-btn{padding: 100rpx 40rpx 0;}
</style>
